﻿using IotClientApp.Server.Entity;
using IotClientApp.Server.Services;
using IotClientApp.Shared;
using Microsoft.AspNetCore.Mvc;

namespace IotClientApp.Server.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class DeviceController : ControllerBase
    {
        private readonly IDeviceService _deviceService;
        public DeviceController(IDeviceService deviceService)
        {
            _deviceService = deviceService;
        }
        /// <summary>
        /// 获取所有设备
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResponse<DeviceInfoModel>> GetDeviceInfos(GetDeviceInfoModel input)
        {
            return await _deviceService.GetDeviceInfos(input);
        }
        /// <summary>
        /// 设备编辑
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<DeviceInfoModel>> SaveDeviceInfo(DeviceInfoModel input)
        {
            return await _deviceService.SaveDeviceInfo(input);
        }
        /// <summary>
        /// 启用/禁用设备采集数据
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="isActive"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<string>> EnableDevice(string deviceId, bool isActive)
        {
            var r = await _deviceService.EnableDevice(deviceId, isActive);
            return r;
        }

        /// <summary>
        /// 下控
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<string>> ControlPoint(ControlPointModel input)
        {
            return await _deviceService.ControlPoint(input);
        }
    }
}